\documentclass[a4paper,12pt,titlepage]{article}

\usepackage[latin1]{inputenc}

\usepackage{latexsym}
\usepackage{url}
\usepackage{graphicx}

\addtolength{\textwidth}{0.5in}
\addtolength{\hoffset}{-0.25in}
\addtolength{\textheight}{1.5in}
\addtolength{\voffset}{-0.8in}

\title{C++ Programming (DATC07)
 \\Course Project: Nusenet}

\author{Johan Ask, CS07 \\
		{snobbslakt@gmail.com } \and
		Oskar Gustafsson, CS07\\
		{oskargustafsson88@gmail.com } \and
		M\"arta Leffler, CS07\\
		{marta.leffler@gmail.com } \and
		Linus Probert, CS07\\
		{linus@probert.se }
}

\date{April 2, 2009}


\begin{document}

\maketitle

\section*{System Design}
In this project we have written a client and two types of servers used to access and manipulate a database of newsgroups and articles. We have used the communication classes and headers given (\texttt{connection}, \texttt{connectionclosedexception}, \texttt{server} and \texttt{protocol}). These will not be discussed in greater detail here. 

\subsection*{Client}
The client functionality is split into two classes - one for handling communication (\texttt{core}) and one for the user interface and parsing input (\texttt{gui}). A \texttt{connection} object is created by the communication class, which contains the necessary methods for sending client requests and handling the servers responses. The \texttt{gui} takes care of interacting with the user, listing valid commands and rejecting invalid ones. Upon receiving a valid command, the \texttt{gui} tells the \texttt{core} to send the appropriate request (see sequence diagram\ref{sec:sequence}). A main class creates a \texttt{core} object  and a \texttt{gui} object, and then ties them together. The \texttt{EDITOR} environment variable must be set on the client side if added articles are to contain any text besides the title and the author's name.

\subsection*{Server}
The server is what connects the client to the database. It is not defined as a class, so there is no way of creating an object of this type, one can only run it as a program. The server initializes the database, creates a \texttt{server} object and then waits for incoming connections. It can handle several connections at once, although not concurrently. If a client sends a malformed request, the server prints an error message and terminates the connection. When a client sends a valid request, the server accesses or manipulates the database  in compliance with the client's wishes and responds with a request adhering to protocol. The in-memory and disk version both exist in the same file, using preprocessing commands specifying what type the generated program should be.

\subsection*{Database}
The database class is basically just a linked list of pairs, where each pair consists of a newsgroup and its list of articles. A database object  is initialized upon creation by reading the directories and files in the directory specified in the header file. The names of the directories in this directory are the newsgroups' ids and names. The class contains methods corresponding to the client requests for listing, adding and deleting newsgroups and articles, and retrieving articles. When adding a newsgroup or article, the new item is assigned a number one greater than the largest id in the enclosing list, much like the autoincrement feature of many popular database management systems. Newsgroups and articles are represented by the structures \texttt{Newsgroup} and \texttt{Article} defined in the database class. A newsgroup has an id and a name, and an article has and id, date, author, title and text. Both overload the $<$-operator. 

\section*{Diagrams}
\subsection*{Class Diagram}
\includegraphics[scale=0.50]{ClassDiagram.pdf}

\subsection*{Sequence Diagram}\label{sec:sequence}
\includegraphics[scale=0.50]{SequenceDiagram.pdf}

\section*{Conclusions}
Overall, we feel that we have met the requirements specified in the project description, the client is quite user friendly and the system is fairly robust. One limitation of our program is that the server cannot find data files if run from anywhere besides the \texttt{bin/} directory in which it resides, as have not dedicated a root directory to the database. Another possible refinement would be to introduce a \texttt{ping}-like method into the client and server. For the moment, the client sends a \texttt{list} request when it enters a newsgroup to test the connection; the addition of a connection test would perhaps be a better idea. 

As for the assignment, we found a bit tricky to find and install a C++ wrapper for MySQL's C API. Although this would take the fun out of programming your own database, using C++ with MySQL would have been somewhat interesting. Maybe implementing a server using a MySQL database could be a bonus part of the project, or perhaps writing your own database could be mandatory and a short description of how one would go about using MySQL could be included in the description.

\end{document}
